package hn.sigit.view;

import hn.sigit.dao.SigitDAO;
import hn.sigit.model.hnd.cadastre.HND_LandUse;

import java.io.Serializable;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Name("selectLandUseHelper")
@Scope(value = ScopeType.CONVERSATION)
@AutoCreate
public class SelectLandUseHelper extends SimpleLandUseHelper implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private HND_LandUse pickedLandUse;
	
	public HND_LandUse getPickedLandUse() {
		return pickedLandUse;
	}
	public void setPickedLandUse(HND_LandUse pickedLandUse) {
		this.pickedLandUse = pickedLandUse;
	}

	public String addIncompatibility() {
		if (getSelected() != null && pickedLandUse != null) {
			getSelected().getIncompatibleLandUses().add(pickedLandUse);
			pickedLandUse.getIncompatibleLandUses().add(getSelected());
			
			SigitDAO.save(getSelected());
			SigitDAO.save(pickedLandUse);
		}
		return null;
	}
	
	public String deleteIncompatibility() {
		if (getSelected() != null && pickedLandUse != null) {
			getSelected().getIncompatibleLandUses().remove(pickedLandUse);
			pickedLandUse.getIncompatibleLandUses().remove(getSelected());
			
			SigitDAO.save(getSelected());
			SigitDAO.save(pickedLandUse);
		}
		return null;
	}
}
